package cn.bearspark.api.controller.main;

import cn.bearspark.api.service.main.CommentService;
import cn.bearspark.api.validation.Enumeration;
import cn.bearspark.api.vo.main.comment.BldgPageVO;
import cn.bearspark.api.vo.main.comment.HappeningReqVO;
import cn.bearspark.api.vo.main.comment.LayerPageVO;
import cn.bearspark.api.vo.main.comment.ReplyReqVO;
import cn.bearspark.comment.enumeration.CommentOrderEnum;
import cn.bearspark.framework.web.starter.vo.ResponseVO;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 评论模块
 *
 * @author f
 */
@Validated
@RestController
@RequestMapping("/comment")
public class CommentController {

    private final CommentService commentService;

    public CommentController(CommentService commentService) {
        this.commentService = commentService;
    }

    /**
     * 分页查询动态的楼评论
     *
     * @param pageNum     评论的页数
     * @param pageSize    评论的条数
     * @param happeningId 待查询评论的动态 id
     * @param order       评论排序的方式
     * @return 楼评论的信息
     */
    @GetMapping("/happening")
    public ResponseVO<BldgPageVO> pageQueryHappening(
            @NotNull Integer pageNum,
            @NotNull Integer pageSize,
            @NotNull Long happeningId,
            @Enumeration(CommentOrderEnum.class) Integer order) {
        return ResponseVO.success(commentService.pageQueryHappening(pageNum, pageSize, happeningId, order));
    }

    /**
     * 分页查询层评论
     *
     * @param pageNum   评论的页数
     * @param pageSize  评论的条数
     * @param commentId 楼评论的 id
     * @return 层评论的信息
     */
    @GetMapping("/layer")
    public ResponseVO<LayerPageVO> pageQueryLayer(@NotNull Integer pageNum,
                                                  @NotNull Integer pageSize,
                                                  @NotNull Long commentId) {
        return ResponseVO.success(commentService.pageQueryLayer(pageNum, pageSize, commentId));
    }

    /**
     * 动态评论 TODO 增加标签的访问量
     *
     * @param happeningReqVO 动态评论的请求对象
     * @return 响应对象
     */
    @PostMapping("/happening")
    public ResponseVO<Object> commentHappening(@Valid @RequestBody HappeningReqVO happeningReqVO) {
        commentService.commentHappening(happeningReqVO);
        return ResponseVO.success();
    }

    /**
     * 回复评论 TODO 增加标签的访问量
     *
     * @param replyReqVO 回复评论的请求对象
     * @return 响应对象
     */
    @PostMapping("/reply")
    public ResponseVO<Object> replyComment(@Valid @RequestBody ReplyReqVO replyReqVO) {
        commentService.replyComment(replyReqVO);
        return ResponseVO.success();
    }

    /**
     * 删除评论
     *
     * @param commentId 待删除评论的 id
     * @return 响应对象
     */
    @DeleteMapping
    public ResponseVO<Object> delete(@NotNull Long commentId) {
        commentService.delete(commentId);
        return ResponseVO.success();
    }

}
